<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title>Spatial Geometry</title>
<link href="../docs-assets/Breadcrumbs.css" rel="stylesheet" rev="stylesheet" type="text/css">
		<meta name="viewport" content="width=device-width initial-scale=1">
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta http-equiv="Content-Language" content="en-gb">

<link href="../docs-assets/Contents.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Progress.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Navigation.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Fonts.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Base.css" rel="stylesheet" rev="stylesheet" type="text/css">
<script>
function togglePopup(material_id) {
  var popup = document.getElementById(material_id);
  popup.classList.toggle("show");
}
</script>

<link href="../docs-assets/Popups.css" rel="stylesheet" rev="stylesheet" type="text/css">
<script>
MathJax = {
	tex: {
		inlineMath: '$', '$'], ['\\(', '\\)'
	},
	svg: {
		fontCache: 'global'
	}
};
</script>
<script type="text/javascript" id="MathJax-script" async
	src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js">
</script>

<link href="../docs-assets/Colours.css" rel="stylesheet" rev="stylesheet" type="text/css">
		
	</head>
	<body class="commentary-font">
		<nav role="navigation">
		<h1><a href="../index.html"><img src="../docs-assets/Inform.png" height=72> </a></h1>
<ul><li><a href="../index.html">home</a></li>
</ul><h2>Compiler</h2><ul>
<li><a href="../structure.html">structure</a></li>
<li><a href="../inbuildn.html">inbuild</a></li>
<li><a href="../inform7n.html">inform7</a></li>
<li><a href="../intern.html">inter</a></li>
<li><a href="../services.html">services</a></li>
<li><a href="../secrets.html">secrets</a></li>
</ul><h2>Other Tools</h2><ul>
<li><a href="../inblorbn.html">inblorb</a></li>
<li><a href="../inform6.html">inform6</a></li>
<li><a href="../inpolicyn.html">inpolicy</a></li>
</ul><h2>Resources</h2><ul>
<li><a href="../extensions.html">extensions</a></li>
<li><a href="../kits.html">kits</a></li>
</ul><h2>Repository</h2><ul>
<li><a href="https://github.com/ganelson/inform"><img src="../docs-assets/github.png" height=0> github</a></li>
</ul><h2>Related Projects</h2><ul>
<li><a href="https://github.com/ganelson/inweb"><img src="../docs-assets/github.png" height=0> inweb</a></li>
<li><a href="https://github.com/ganelson/intest"><img src="../docs-assets/github.png" height=0> intest</a></li>
</ul>
		</nav>
		<main role="main">
		<!-- Weave of 'Spatial Geometry' generated by inweb -->
<div class="breadcrumbs">
    <ul class="crumbs"><li><a href="../index.html">Home</a></li><li><a href="../intern.html">Inter Modules</a></li><li><a href="index.html">index</a></li><li><a href="index.html#4">Chapter 4: Spatial Mapping</a></li><li><b>Spatial Geometry</b></li></ul></div>
<p class="purpose">Simple mathematical functions for dealing with vectors and cuboids in a three-dimensional integer lattice.</p>

<ul class="toc"><li><a href="4-sg.html#SP5">&#167;5. Vectors</a></li><li><a href="4-sg.html#SP8">&#167;8. Lengths</a></li><li><a href="4-sg.html#SP9">&#167;9. Angles</a></li><li><a href="4-sg.html#SP10">&#167;10. Cuboids</a></li></ul><hr class="tocbar">

<p class="commentary firstcommentary"><a id="SP1" class="paragraph-anchor"></a><b>&#167;1. </b>We will store 3-vectors in the obvious way:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">typedef</span><span class="plain-syntax"> </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">vector</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">x</span><span class="plain-syntax">, </span><span class="identifier-syntax">y</span><span class="plain-syntax">, </span><span class="identifier-syntax">z</span><span class="plain-syntax">;</span>
<span class="plain-syntax">} </span><span class="reserved-syntax">vector</span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>The structure vector is accessed in 4/sm, 4/rhm, 4/rem and here.</li></ul>
<p class="commentary firstcommentary"><a id="SP2" class="paragraph-anchor"></a><b>&#167;2. </b>Some useful constant vectors:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">vector</span><span class="plain-syntax"> </span><span class="identifier-syntax">Zero_vector</span><span class="plain-syntax"> = {0, </span><span class="constant-syntax">0</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">};</span>

<span class="reserved-syntax">vector</span><span class="plain-syntax"> </span><span class="function-syntax">Geometry::zero</span><button class="popup" onclick="togglePopup('usagePopup1')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup1">Usage of <span class="code-font"><span class="function-syntax">Geometry::zero</span></span>:<br/>Faux Instances - <a href="2-fi.html#SP4">&#167;4</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">void</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">Zero_vector</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP3" class="paragraph-anchor"></a><b>&#167;3. </b>Now for vectors pointing in each direction. Note that not all of these are of
unit length &mdash; rather, they are the ideal grid offsets on the map we will
eventually draw.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">vector</span><span class="plain-syntax"> </span><span class="identifier-syntax">N_vector</span><span class="plain-syntax"> = {0, </span><span class="constant-syntax">1</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">};</span>
<span class="reserved-syntax">vector</span><span class="plain-syntax"> </span><span class="identifier-syntax">NE_vector</span><span class="plain-syntax"> = {1, </span><span class="constant-syntax">1</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">};</span>
<span class="reserved-syntax">vector</span><span class="plain-syntax"> </span><span class="identifier-syntax">NW_vector</span><span class="plain-syntax"> = {-1, </span><span class="constant-syntax">1</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">};</span>
<span class="reserved-syntax">vector</span><span class="plain-syntax"> </span><span class="identifier-syntax">S_vector</span><span class="plain-syntax"> = {0, -1, </span><span class="constant-syntax">0</span><span class="plain-syntax">};</span>
<span class="reserved-syntax">vector</span><span class="plain-syntax"> </span><span class="identifier-syntax">SE_vector</span><span class="plain-syntax"> = {1, -1, </span><span class="constant-syntax">0</span><span class="plain-syntax">};</span>
<span class="reserved-syntax">vector</span><span class="plain-syntax"> </span><span class="identifier-syntax">SW_vector</span><span class="plain-syntax"> = {-1, -1, </span><span class="constant-syntax">0</span><span class="plain-syntax">};</span>
<span class="reserved-syntax">vector</span><span class="plain-syntax"> </span><span class="identifier-syntax">E_vector</span><span class="plain-syntax"> = {1, </span><span class="constant-syntax">0</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">};</span>
<span class="reserved-syntax">vector</span><span class="plain-syntax"> </span><span class="identifier-syntax">W_vector</span><span class="plain-syntax"> = {-1, </span><span class="constant-syntax">0</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">};</span>
<span class="reserved-syntax">vector</span><span class="plain-syntax"> </span><span class="identifier-syntax">U_vector</span><span class="plain-syntax"> = {0, </span><span class="constant-syntax">0</span><span class="plain-syntax">, </span><span class="constant-syntax">1</span><span class="plain-syntax">};</span>
<span class="reserved-syntax">vector</span><span class="plain-syntax"> </span><span class="identifier-syntax">D_vector</span><span class="plain-syntax"> = {0, </span><span class="constant-syntax">0</span><span class="plain-syntax">, -1};</span>
</pre>
<p class="commentary firstcommentary"><a id="SP4" class="paragraph-anchor"></a><b>&#167;4. </b>A cuboid is a volume of space with opposing corners at integer grid
positions which form a tightest-possible bounding box around a finite
number of points (of size <span class="extract"><span class="extract-syntax">population</span></span>); when this is 0, of course, the
corners are meaningless and are by convention at the origin.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">typedef</span><span class="plain-syntax"> </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">cuboid</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">population</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">vector</span><span class="plain-syntax"> </span><span class="identifier-syntax">corner0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">vector</span><span class="plain-syntax"> </span><span class="identifier-syntax">corner1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">} </span><span class="reserved-syntax">cuboid</span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>The structure cuboid is accessed in 4/sm, 4/rhm, 4/rem and here.</li></ul>
<p class="commentary firstcommentary"><a id="SP5" class="paragraph-anchor"></a><b>&#167;5. Vectors.</b></p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">vector</span><span class="plain-syntax"> </span><span class="function-syntax">Geometry::vec</span><button class="popup" onclick="togglePopup('usagePopup2')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup2">Usage of <span class="code-font"><span class="function-syntax">Geometry::vec</span></span>:<br/>Spatial Map - <a href="4-sm.html#SP30_1">&#167;30.1</a>, <a href="4-sm.html#SP63">&#167;63</a>, <a href="4-sm.html#SP8_4_1_1">&#167;8.4.1.1</a>, <a href="4-sm.html#SP8_4_1_2">&#167;8.4.1.2</a>, <a href="4-sm.html#SP8_4_1_3">&#167;8.4.1.3</a><br/>Render HTML Map - <a href="4-rhm.html#SP14">&#167;14</a>, <a href="4-rhm.html#SP14_2_1_1">&#167;14.2.1.1</a>, <a href="4-rhm.html#SP14_2_2_1">&#167;14.2.2.1</a>, <a href="4-rhm.html#SP14_2_3_1">&#167;14.2.3.1</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">x</span><span class="plain-syntax">, </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">y</span><span class="plain-syntax">, </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">z</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">vector</span><span class="plain-syntax"> </span><span class="identifier-syntax">R</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">R</span><span class="plain-syntax">.</span><span class="element-syntax">x</span><span class="plain-syntax"> = </span><span class="identifier-syntax">x</span><span class="plain-syntax">; </span><span class="identifier-syntax">R</span><span class="plain-syntax">.</span><span class="identifier-syntax">y</span><span class="plain-syntax"> = </span><span class="identifier-syntax">y</span><span class="plain-syntax">; </span><span class="identifier-syntax">R</span><span class="plain-syntax">.</span><span class="identifier-syntax">z</span><span class="plain-syntax"> = </span><span class="identifier-syntax">z</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">R</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP6" class="paragraph-anchor"></a><b>&#167;6. </b>A vector is "lateral" if lies in the \(x\)-\(y\) plane.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">Geometry::vec_eq</span><button class="popup" onclick="togglePopup('usagePopup3')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup3">Usage of <span class="code-font"><span class="function-syntax">Geometry::vec_eq</span></span>:<br/>Spatial Map - <a href="4-sm.html#SP17">&#167;17</a>, <a href="4-sm.html#SP45">&#167;45</a>, <a href="4-sm.html#SP46">&#167;46</a>, <a href="4-sm.html#SP57">&#167;57</a><br/>Render HTML Map - <a href="4-rhm.html#SP1_3_1">&#167;1.3.1</a>, <a href="4-rhm.html#SP1_3_1_1">&#167;1.3.1.1</a>, <a href="4-rhm.html#SP1_3_1_2">&#167;1.3.1.2</a>, <a href="4-rhm.html#SP5_1">&#167;5.1</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">vector</span><span class="plain-syntax"> </span><span class="identifier-syntax">U</span><span class="plain-syntax">, </span><span class="reserved-syntax">vector</span><span class="plain-syntax"> </span><span class="identifier-syntax">V</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">U</span><span class="plain-syntax">.</span><span class="element-syntax">x</span><span class="plain-syntax"> == </span><span class="identifier-syntax">V</span><span class="plain-syntax">.</span><span class="element-syntax">x</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">U</span><span class="plain-syntax">.</span><span class="identifier-syntax">y</span><span class="plain-syntax"> == </span><span class="identifier-syntax">V</span><span class="plain-syntax">.</span><span class="identifier-syntax">y</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">U</span><span class="plain-syntax">.</span><span class="identifier-syntax">z</span><span class="plain-syntax"> == </span><span class="identifier-syntax">V</span><span class="plain-syntax">.</span><span class="identifier-syntax">z</span><span class="plain-syntax">)) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">Geometry::vec_lateral</span><button class="popup" onclick="togglePopup('usagePopup4')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup4">Usage of <span class="code-font"><span class="function-syntax">Geometry::vec_lateral</span></span>:<br/>Spatial Map - <a href="4-sm.html#SP16">&#167;16</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">vector</span><span class="plain-syntax"> </span><span class="identifier-syntax">V</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">V</span><span class="plain-syntax">.</span><span class="element-syntax">x</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">V</span><span class="plain-syntax">.</span><span class="identifier-syntax">y</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">)) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP7" class="paragraph-anchor"></a><b>&#167;7. </b>The vector space operations:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">vector</span><span class="plain-syntax"> </span><span class="function-syntax">Geometry::vec_plus</span><button class="popup" onclick="togglePopup('usagePopup5')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup5">Usage of <span class="code-font"><span class="function-syntax">Geometry::vec_plus</span></span>:<br/><a href="4-sg.html#SP12">&#167;12</a>, <a href="4-sg.html#SP15">&#167;15</a><br/>Spatial Map - <a href="4-sm.html#SP34">&#167;34</a>, <a href="4-sm.html#SP38">&#167;38</a>, <a href="4-sm.html#SP39">&#167;39</a>, <a href="4-sm.html#SP45">&#167;45</a>, <a href="4-sm.html#SP47_1_4_1">&#167;47.1.4.1</a>, <a href="4-sm.html#SP57">&#167;57</a>, <a href="4-sm.html#SP61_1">&#167;61.1</a>, <a href="4-sm.html#SP63">&#167;63</a>, <a href="4-sm.html#SP8_4_1_2">&#167;8.4.1.2</a>, <a href="4-sm.html#SP8_4_1_3">&#167;8.4.1.3</a><br/>Render HTML Map - <a href="4-rhm.html#SP1_3_1_2">&#167;1.3.1.2</a>, <a href="4-rhm.html#SP5">&#167;5</a>, <a href="4-rhm.html#SP5_1">&#167;5.1</a>, <a href="4-rhm.html#SP6">&#167;6</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">vector</span><span class="plain-syntax"> </span><span class="identifier-syntax">U</span><span class="plain-syntax">, </span><span class="reserved-syntax">vector</span><span class="plain-syntax"> </span><span class="identifier-syntax">V</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">vector</span><span class="plain-syntax"> </span><span class="identifier-syntax">R</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">R</span><span class="plain-syntax">.</span><span class="element-syntax">x</span><span class="plain-syntax"> = </span><span class="identifier-syntax">U</span><span class="plain-syntax">.</span><span class="element-syntax">x</span><span class="plain-syntax"> + </span><span class="identifier-syntax">V</span><span class="plain-syntax">.</span><span class="element-syntax">x</span><span class="plain-syntax">; </span><span class="identifier-syntax">R</span><span class="plain-syntax">.</span><span class="identifier-syntax">y</span><span class="plain-syntax"> = </span><span class="identifier-syntax">U</span><span class="plain-syntax">.</span><span class="identifier-syntax">y</span><span class="plain-syntax"> + </span><span class="identifier-syntax">V</span><span class="plain-syntax">.</span><span class="identifier-syntax">y</span><span class="plain-syntax">; </span><span class="identifier-syntax">R</span><span class="plain-syntax">.</span><span class="identifier-syntax">z</span><span class="plain-syntax"> = </span><span class="identifier-syntax">U</span><span class="plain-syntax">.</span><span class="identifier-syntax">z</span><span class="plain-syntax"> + </span><span class="identifier-syntax">V</span><span class="plain-syntax">.</span><span class="identifier-syntax">z</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">R</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">vector</span><span class="plain-syntax"> </span><span class="function-syntax">Geometry::vec_minus</span><button class="popup" onclick="togglePopup('usagePopup6')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup6">Usage of <span class="code-font"><span class="function-syntax">Geometry::vec_minus</span></span>:<br/><a href="4-sg.html#SP14">&#167;14</a>, <a href="4-sg.html#SP15">&#167;15</a><br/>Spatial Map - <a href="4-sm.html#SP45">&#167;45</a>, <a href="4-sm.html#SP46">&#167;46</a>, <a href="4-sm.html#SP47_1_4_1">&#167;47.1.4.1</a>, <a href="4-sm.html#SP59_1">&#167;59.1</a>, <a href="4-sm.html#SP8_4_1_2">&#167;8.4.1.2</a>, <a href="4-sm.html#SP8_4_1_3">&#167;8.4.1.3</a>, <a href="4-sm.html#SP69">&#167;69</a><br/>Render HTML Map - <a href="4-rhm.html#SP1_3_1_1">&#167;1.3.1.1</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">vector</span><span class="plain-syntax"> </span><span class="identifier-syntax">U</span><span class="plain-syntax">, </span><span class="reserved-syntax">vector</span><span class="plain-syntax"> </span><span class="identifier-syntax">V</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">vector</span><span class="plain-syntax"> </span><span class="identifier-syntax">R</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">R</span><span class="plain-syntax">.</span><span class="element-syntax">x</span><span class="plain-syntax"> = </span><span class="identifier-syntax">U</span><span class="plain-syntax">.</span><span class="element-syntax">x</span><span class="plain-syntax"> - </span><span class="identifier-syntax">V</span><span class="plain-syntax">.</span><span class="element-syntax">x</span><span class="plain-syntax">; </span><span class="identifier-syntax">R</span><span class="plain-syntax">.</span><span class="identifier-syntax">y</span><span class="plain-syntax"> = </span><span class="identifier-syntax">U</span><span class="plain-syntax">.</span><span class="identifier-syntax">y</span><span class="plain-syntax"> - </span><span class="identifier-syntax">V</span><span class="plain-syntax">.</span><span class="identifier-syntax">y</span><span class="plain-syntax">; </span><span class="identifier-syntax">R</span><span class="plain-syntax">.</span><span class="identifier-syntax">z</span><span class="plain-syntax"> = </span><span class="identifier-syntax">U</span><span class="plain-syntax">.</span><span class="identifier-syntax">z</span><span class="plain-syntax"> - </span><span class="identifier-syntax">V</span><span class="plain-syntax">.</span><span class="identifier-syntax">z</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">R</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">vector</span><span class="plain-syntax"> </span><span class="function-syntax">Geometry::vec_negate</span><button class="popup" onclick="togglePopup('usagePopup7')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup7">Usage of <span class="code-font"><span class="function-syntax">Geometry::vec_negate</span></span>:<br/>Spatial Map - <a href="4-sm.html#SP8_4_1_3_1">&#167;8.4.1.3.1</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">vector</span><span class="plain-syntax"> </span><span class="identifier-syntax">V</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">vector</span><span class="plain-syntax"> </span><span class="identifier-syntax">R</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">R</span><span class="plain-syntax">.</span><span class="element-syntax">x</span><span class="plain-syntax"> = -</span><span class="identifier-syntax">V</span><span class="plain-syntax">.</span><span class="element-syntax">x</span><span class="plain-syntax">; </span><span class="identifier-syntax">R</span><span class="plain-syntax">.</span><span class="identifier-syntax">y</span><span class="plain-syntax"> = -</span><span class="identifier-syntax">V</span><span class="plain-syntax">.</span><span class="identifier-syntax">y</span><span class="plain-syntax">; </span><span class="identifier-syntax">R</span><span class="plain-syntax">.</span><span class="identifier-syntax">z</span><span class="plain-syntax"> = -</span><span class="identifier-syntax">V</span><span class="plain-syntax">.</span><span class="identifier-syntax">z</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">R</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">vector</span><span class="plain-syntax"> </span><span class="function-syntax">Geometry::vec_scale</span><button class="popup" onclick="togglePopup('usagePopup8')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup8">Usage of <span class="code-font"><span class="function-syntax">Geometry::vec_scale</span></span>:<br/>Spatial Map - <a href="4-sm.html#SP47_1_4_1">&#167;47.1.4.1</a>, <a href="4-sm.html#SP57">&#167;57</a>, <a href="4-sm.html#SP61_1">&#167;61.1</a><br/>Render HTML Map - <a href="4-rhm.html#SP1_3_1_1">&#167;1.3.1.1</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">lambda</span><span class="plain-syntax">, </span><span class="reserved-syntax">vector</span><span class="plain-syntax"> </span><span class="identifier-syntax">V</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">vector</span><span class="plain-syntax"> </span><span class="identifier-syntax">R</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">R</span><span class="plain-syntax">.</span><span class="element-syntax">x</span><span class="plain-syntax"> = </span><span class="identifier-syntax">lambda</span><span class="plain-syntax">*</span><span class="identifier-syntax">V</span><span class="plain-syntax">.</span><span class="element-syntax">x</span><span class="plain-syntax">; </span><span class="identifier-syntax">R</span><span class="plain-syntax">.</span><span class="identifier-syntax">y</span><span class="plain-syntax"> = </span><span class="identifier-syntax">lambda</span><span class="plain-syntax">*</span><span class="identifier-syntax">V</span><span class="plain-syntax">.</span><span class="identifier-syntax">y</span><span class="plain-syntax">; </span><span class="identifier-syntax">R</span><span class="plain-syntax">.</span><span class="identifier-syntax">z</span><span class="plain-syntax"> = </span><span class="identifier-syntax">lambda</span><span class="plain-syntax">*</span><span class="identifier-syntax">V</span><span class="plain-syntax">.</span><span class="identifier-syntax">z</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">R</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP8" class="paragraph-anchor"></a><b>&#167;8. Lengths.</b></p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">Geometry::vec_length_squared</span><button class="popup" onclick="togglePopup('usagePopup9')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup9">Usage of <span class="code-font"><span class="function-syntax">Geometry::vec_length_squared</span></span>:<br/>Spatial Map - <a href="4-sm.html#SP45">&#167;45</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">vector</span><span class="plain-syntax"> </span><span class="identifier-syntax">V</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">V</span><span class="plain-syntax">.</span><span class="element-syntax">x</span><span class="plain-syntax">*</span><span class="identifier-syntax">V</span><span class="plain-syntax">.</span><span class="element-syntax">x</span><span class="plain-syntax"> + </span><span class="identifier-syntax">V</span><span class="plain-syntax">.</span><span class="identifier-syntax">y</span><span class="plain-syntax">*</span><span class="identifier-syntax">V</span><span class="plain-syntax">.</span><span class="identifier-syntax">y</span><span class="plain-syntax"> + </span><span class="identifier-syntax">V</span><span class="plain-syntax">.</span><span class="identifier-syntax">z</span><span class="plain-syntax">*</span><span class="identifier-syntax">V</span><span class="plain-syntax">.</span><span class="identifier-syntax">z</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">float</span><span class="plain-syntax"> </span><span class="function-syntax">Geometry::vec_length</span><button class="popup" onclick="togglePopup('usagePopup10')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup10">Usage of <span class="code-font"><span class="function-syntax">Geometry::vec_length</span></span>:<br/><a href="4-sg.html#SP9">&#167;9</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">vector</span><span class="plain-syntax"> </span><span class="identifier-syntax">V</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> (</span><span class="reserved-syntax">float</span><span class="plain-syntax">) (</span><span class="identifier-syntax">sqrt</span><span class="plain-syntax">(</span><a href="4-sg.html#SP8" class="function-link"><span class="function-syntax">Geometry::vec_length_squared</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">V</span><span class="plain-syntax">)));</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP9" class="paragraph-anchor"></a><b>&#167;9. Angles.</b>We compute unit vectors in the D and E directions and then the squared
length of their difference. This is a fairly sharply increasing function of
the absolute value of the angular difference between D and E, and is such
that if the angles are equal then the result is zero; and it's cheap to
compute. So although it might seem nicer to calculate actual angles, this
is better.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">float</span><span class="plain-syntax"> </span><span class="function-syntax">Geometry::vec_angular_separation</span><button class="popup" onclick="togglePopup('usagePopup11')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup11">Usage of <span class="code-font"><span class="function-syntax">Geometry::vec_angular_separation</span></span>:<br/>Spatial Map - <a href="4-sm.html#SP45">&#167;45</a>, <a href="4-sm.html#SP46">&#167;46</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">vector</span><span class="plain-syntax"> </span><span class="identifier-syntax">E</span><span class="plain-syntax">, </span><span class="reserved-syntax">vector</span><span class="plain-syntax"> </span><span class="identifier-syntax">D</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">float</span><span class="plain-syntax"> </span><span class="identifier-syntax">E_distance</span><span class="plain-syntax"> = </span><a href="4-sg.html#SP8" class="function-link"><span class="function-syntax">Geometry::vec_length</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">E</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">float</span><span class="plain-syntax"> </span><span class="identifier-syntax">uex</span><span class="plain-syntax"> = </span><span class="identifier-syntax">E</span><span class="plain-syntax">.</span><span class="element-syntax">x</span><span class="plain-syntax">/</span><span class="identifier-syntax">E_distance</span><span class="plain-syntax">, </span><span class="identifier-syntax">uey</span><span class="plain-syntax"> = </span><span class="identifier-syntax">E</span><span class="plain-syntax">.</span><span class="identifier-syntax">y</span><span class="plain-syntax">/</span><span class="identifier-syntax">E_distance</span><span class="plain-syntax">, </span><span class="identifier-syntax">uez</span><span class="plain-syntax"> = </span><span class="identifier-syntax">E</span><span class="plain-syntax">.</span><span class="identifier-syntax">z</span><span class="plain-syntax">/</span><span class="identifier-syntax">E_distance</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">float</span><span class="plain-syntax"> </span><span class="identifier-syntax">D_distance</span><span class="plain-syntax"> = </span><a href="4-sg.html#SP8" class="function-link"><span class="function-syntax">Geometry::vec_length</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">D</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">float</span><span class="plain-syntax"> </span><span class="identifier-syntax">udx</span><span class="plain-syntax"> = </span><span class="identifier-syntax">D</span><span class="plain-syntax">.</span><span class="element-syntax">x</span><span class="plain-syntax">/</span><span class="identifier-syntax">D_distance</span><span class="plain-syntax">, </span><span class="identifier-syntax">udy</span><span class="plain-syntax"> = </span><span class="identifier-syntax">D</span><span class="plain-syntax">.</span><span class="identifier-syntax">y</span><span class="plain-syntax">/</span><span class="identifier-syntax">D_distance</span><span class="plain-syntax">, </span><span class="identifier-syntax">udz</span><span class="plain-syntax"> = </span><span class="identifier-syntax">D</span><span class="plain-syntax">.</span><span class="identifier-syntax">z</span><span class="plain-syntax">/</span><span class="identifier-syntax">D_distance</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> (</span><span class="identifier-syntax">uex</span><span class="plain-syntax">-</span><span class="identifier-syntax">udx</span><span class="plain-syntax">)*(</span><span class="identifier-syntax">uex</span><span class="plain-syntax">-</span><span class="identifier-syntax">udx</span><span class="plain-syntax">) + (</span><span class="identifier-syntax">uey</span><span class="plain-syntax">-</span><span class="identifier-syntax">udy</span><span class="plain-syntax">)*(</span><span class="identifier-syntax">uey</span><span class="plain-syntax">-</span><span class="identifier-syntax">udy</span><span class="plain-syntax">) + (</span><span class="identifier-syntax">uez</span><span class="plain-syntax">-</span><span class="identifier-syntax">udz</span><span class="plain-syntax">)*(</span><span class="identifier-syntax">uez</span><span class="plain-syntax">-</span><span class="identifier-syntax">udz</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP10" class="paragraph-anchor"></a><b>&#167;10. Cuboids.</b>To form a populated cuboid, first request an empty one, and then adjust it
for each vector to join the population.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">cuboid</span><span class="plain-syntax"> </span><span class="function-syntax">Geometry::empty_cuboid</span><button class="popup" onclick="togglePopup('usagePopup12')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup12">Usage of <span class="code-font"><span class="function-syntax">Geometry::empty_cuboid</span></span>:<br/>Spatial Map - <a href="4-sm.html#SP7">&#167;7</a>, <a href="4-sm.html#SP25">&#167;25</a>, <a href="4-sm.html#SP31">&#167;31</a>, <a href="4-sm.html#SP43">&#167;43</a>, <a href="4-sm.html#SP8_4">&#167;8.4</a>, <a href="4-sm.html#SP8_5">&#167;8.5</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">void</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">cuboid</span><span class="plain-syntax"> </span><span class="identifier-syntax">C</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">C</span><span class="plain-syntax">.</span><span class="element-syntax">population</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">C</span><span class="plain-syntax">.</span><span class="element-syntax">corner0</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Zero_vector</span><span class="plain-syntax">; </span><span class="identifier-syntax">C</span><span class="plain-syntax">.</span><span class="element-syntax">corner1</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Zero_vector</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">C</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Geometry::adjust_cuboid</span><button class="popup" onclick="togglePopup('usagePopup13')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup13">Usage of <span class="code-font"><span class="function-syntax">Geometry::adjust_cuboid</span></span>:<br/><a href="4-sg.html#SP11">&#167;11</a><br/>Spatial Map - <a href="4-sm.html#SP43">&#167;43</a>, <a href="4-sm.html#SP8_5">&#167;8.5</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">cuboid</span><span class="plain-syntax"> *</span><span class="identifier-syntax">C</span><span class="plain-syntax">, </span><span class="reserved-syntax">vector</span><span class="plain-syntax"> </span><span class="identifier-syntax">V</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">population</span><span class="plain-syntax">++ == </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">corner0</span><span class="plain-syntax"> = </span><span class="identifier-syntax">V</span><span class="plain-syntax">; </span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">corner1</span><span class="plain-syntax"> = </span><span class="identifier-syntax">V</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">V</span><span class="plain-syntax">.</span><span class="element-syntax">x</span><span class="plain-syntax"> &lt; </span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">corner0</span><span class="plain-syntax">.</span><span class="element-syntax">x</span><span class="plain-syntax">) </span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">corner0</span><span class="plain-syntax">.</span><span class="element-syntax">x</span><span class="plain-syntax"> = </span><span class="identifier-syntax">V</span><span class="plain-syntax">.</span><span class="element-syntax">x</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">V</span><span class="plain-syntax">.</span><span class="element-syntax">x</span><span class="plain-syntax"> &gt; </span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">corner1</span><span class="plain-syntax">.</span><span class="element-syntax">x</span><span class="plain-syntax">) </span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">corner1</span><span class="plain-syntax">.</span><span class="element-syntax">x</span><span class="plain-syntax"> = </span><span class="identifier-syntax">V</span><span class="plain-syntax">.</span><span class="element-syntax">x</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">V</span><span class="plain-syntax">.</span><span class="identifier-syntax">y</span><span class="plain-syntax"> &lt; </span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">corner0</span><span class="plain-syntax">.</span><span class="identifier-syntax">y</span><span class="plain-syntax">) </span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">corner0</span><span class="plain-syntax">.</span><span class="identifier-syntax">y</span><span class="plain-syntax"> = </span><span class="identifier-syntax">V</span><span class="plain-syntax">.</span><span class="identifier-syntax">y</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">V</span><span class="plain-syntax">.</span><span class="identifier-syntax">y</span><span class="plain-syntax"> &gt; </span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">corner1</span><span class="plain-syntax">.</span><span class="identifier-syntax">y</span><span class="plain-syntax">) </span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">corner1</span><span class="plain-syntax">.</span><span class="identifier-syntax">y</span><span class="plain-syntax"> = </span><span class="identifier-syntax">V</span><span class="plain-syntax">.</span><span class="identifier-syntax">y</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">V</span><span class="plain-syntax">.</span><span class="identifier-syntax">z</span><span class="plain-syntax"> &lt; </span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">corner0</span><span class="plain-syntax">.</span><span class="identifier-syntax">z</span><span class="plain-syntax">) </span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">corner0</span><span class="plain-syntax">.</span><span class="identifier-syntax">z</span><span class="plain-syntax"> = </span><span class="identifier-syntax">V</span><span class="plain-syntax">.</span><span class="identifier-syntax">z</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">V</span><span class="plain-syntax">.</span><span class="identifier-syntax">z</span><span class="plain-syntax"> &gt; </span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">corner1</span><span class="plain-syntax">.</span><span class="identifier-syntax">z</span><span class="plain-syntax">) </span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">corner1</span><span class="plain-syntax">.</span><span class="identifier-syntax">z</span><span class="plain-syntax"> = </span><span class="identifier-syntax">V</span><span class="plain-syntax">.</span><span class="identifier-syntax">z</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP11" class="paragraph-anchor"></a><b>&#167;11. </b>The following expands \(C\) minimally so that it contains \(X\).
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Geometry::merge_cuboid</span><button class="popup" onclick="togglePopup('usagePopup14')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup14">Usage of <span class="code-font"><span class="function-syntax">Geometry::merge_cuboid</span></span>:<br/>Spatial Map - <a href="4-sm.html#SP8_4_1">&#167;8.4.1</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">cuboid</span><span class="plain-syntax"> *</span><span class="identifier-syntax">C</span><span class="plain-syntax">, </span><span class="reserved-syntax">cuboid</span><span class="plain-syntax"> </span><span class="identifier-syntax">X</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">X</span><span class="plain-syntax">.</span><span class="element-syntax">population</span><span class="plain-syntax"> &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">population</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            *</span><span class="identifier-syntax">C</span><span class="plain-syntax"> = </span><span class="identifier-syntax">X</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">            </span><a href="4-sg.html#SP10" class="function-link"><span class="function-syntax">Geometry::adjust_cuboid</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">C</span><span class="plain-syntax">, </span><span class="identifier-syntax">X</span><span class="plain-syntax">.</span><span class="element-syntax">corner0</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><a href="4-sg.html#SP10" class="function-link"><span class="function-syntax">Geometry::adjust_cuboid</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">C</span><span class="plain-syntax">, </span><span class="identifier-syntax">X</span><span class="plain-syntax">.</span><span class="element-syntax">corner1</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">population</span><span class="plain-syntax"> += </span><span class="identifier-syntax">X</span><span class="plain-syntax">.</span><span class="element-syntax">population</span><span class="plain-syntax"> - </span><span class="constant-syntax">2</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP12" class="paragraph-anchor"></a><b>&#167;12. </b>Here we shift an entire cuboid over (assuming all of the points inside
it have made the same shift).
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Geometry::cuboid_translate</span><button class="popup" onclick="togglePopup('usagePopup15')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup15">Usage of <span class="code-font"><span class="function-syntax">Geometry::cuboid_translate</span></span>:<br/>Spatial Map - <a href="4-sm.html#SP34">&#167;34</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">cuboid</span><span class="plain-syntax"> *</span><span class="identifier-syntax">C</span><span class="plain-syntax">, </span><span class="reserved-syntax">vector</span><span class="plain-syntax"> </span><span class="identifier-syntax">D</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">population</span><span class="plain-syntax"> &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">corner0</span><span class="plain-syntax"> = </span><a href="4-sg.html#SP7" class="function-link"><span class="function-syntax">Geometry::vec_plus</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">corner0</span><span class="plain-syntax">, </span><span class="identifier-syntax">D</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">corner1</span><span class="plain-syntax"> = </span><a href="4-sg.html#SP7" class="function-link"><span class="function-syntax">Geometry::vec_plus</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">corner1</span><span class="plain-syntax">, </span><span class="identifier-syntax">D</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP13" class="paragraph-anchor"></a><b>&#167;13. </b></p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">Geometry::within_cuboid</span><button class="popup" onclick="togglePopup('usagePopup16')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup16">Usage of <span class="code-font"><span class="function-syntax">Geometry::within_cuboid</span></span>:<br/><a href="4-sg.html#SP14">&#167;14</a><br/>Spatial Map - <a href="4-sm.html#SP30">&#167;30</a><br/>Render HTML Map - <a href="4-rhm.html#SP5">&#167;5</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">vector</span><span class="plain-syntax"> </span><span class="identifier-syntax">P</span><span class="plain-syntax">, </span><span class="reserved-syntax">cuboid</span><span class="plain-syntax"> </span><span class="identifier-syntax">C</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">C</span><span class="plain-syntax">.</span><span class="element-syntax">population</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">P</span><span class="plain-syntax">.</span><span class="element-syntax">x</span><span class="plain-syntax"> &lt; </span><span class="identifier-syntax">C</span><span class="plain-syntax">.</span><span class="element-syntax">corner0</span><span class="plain-syntax">.</span><span class="element-syntax">x</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">P</span><span class="plain-syntax">.</span><span class="element-syntax">x</span><span class="plain-syntax"> &gt; </span><span class="identifier-syntax">C</span><span class="plain-syntax">.</span><span class="element-syntax">corner1</span><span class="plain-syntax">.</span><span class="element-syntax">x</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">P</span><span class="plain-syntax">.</span><span class="identifier-syntax">y</span><span class="plain-syntax"> &lt; </span><span class="identifier-syntax">C</span><span class="plain-syntax">.</span><span class="element-syntax">corner0</span><span class="plain-syntax">.</span><span class="identifier-syntax">y</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">P</span><span class="plain-syntax">.</span><span class="identifier-syntax">y</span><span class="plain-syntax"> &gt; </span><span class="identifier-syntax">C</span><span class="plain-syntax">.</span><span class="element-syntax">corner1</span><span class="plain-syntax">.</span><span class="identifier-syntax">y</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">P</span><span class="plain-syntax">.</span><span class="identifier-syntax">z</span><span class="plain-syntax"> &lt; </span><span class="identifier-syntax">C</span><span class="plain-syntax">.</span><span class="element-syntax">corner0</span><span class="plain-syntax">.</span><span class="identifier-syntax">z</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">P</span><span class="plain-syntax">.</span><span class="identifier-syntax">z</span><span class="plain-syntax"> &gt; </span><span class="identifier-syntax">C</span><span class="plain-syntax">.</span><span class="element-syntax">corner1</span><span class="plain-syntax">.</span><span class="identifier-syntax">z</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP14" class="paragraph-anchor"></a><b>&#167;14. </b>Suppose we have a one-dimensional array whose entries correspond to the
integer grid positions within a cuboid (including its faces and corners).
The following returns \(-1\) if a point is outside the cuboid, or returns
the index if it is.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">Geometry::cuboid_index</span><button class="popup" onclick="togglePopup('usagePopup17')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup17">Usage of <span class="code-font"><span class="function-syntax">Geometry::cuboid_index</span></span>:<br/>Spatial Map - <a href="4-sm.html#SP28">&#167;28</a>, <a href="4-sm.html#SP30">&#167;30</a>, <a href="4-sm.html#SP30_1">&#167;30.1</a><br/>Render HTML Map - <a href="4-rhm.html#SP1">&#167;1</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">vector</span><span class="plain-syntax"> </span><span class="identifier-syntax">P</span><span class="plain-syntax">, </span><span class="reserved-syntax">cuboid</span><span class="plain-syntax"> </span><span class="identifier-syntax">C</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="4-sg.html#SP13" class="function-link"><span class="function-syntax">Geometry::within_cuboid</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">, </span><span class="identifier-syntax">C</span><span class="plain-syntax">) == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> -1;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">vector</span><span class="plain-syntax"> </span><span class="identifier-syntax">O</span><span class="plain-syntax"> = </span><a href="4-sg.html#SP7" class="function-link"><span class="function-syntax">Geometry::vec_minus</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">, </span><span class="identifier-syntax">C</span><span class="plain-syntax">.</span><span class="element-syntax">corner0</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">width</span><span class="plain-syntax">  = </span><span class="identifier-syntax">C</span><span class="plain-syntax">.</span><span class="element-syntax">corner1</span><span class="plain-syntax">.</span><span class="element-syntax">x</span><span class="plain-syntax"> - </span><span class="identifier-syntax">C</span><span class="plain-syntax">.</span><span class="element-syntax">corner0</span><span class="plain-syntax">.</span><span class="element-syntax">x</span><span class="plain-syntax"> + </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">height</span><span class="plain-syntax"> = </span><span class="identifier-syntax">C</span><span class="plain-syntax">.</span><span class="element-syntax">corner1</span><span class="plain-syntax">.</span><span class="identifier-syntax">y</span><span class="plain-syntax"> - </span><span class="identifier-syntax">C</span><span class="plain-syntax">.</span><span class="element-syntax">corner0</span><span class="plain-syntax">.</span><span class="identifier-syntax">y</span><span class="plain-syntax"> + </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">O</span><span class="plain-syntax">.</span><span class="element-syntax">x</span><span class="plain-syntax"> + </span><span class="identifier-syntax">O</span><span class="plain-syntax">.</span><span class="identifier-syntax">y</span><span class="plain-syntax">*</span><span class="identifier-syntax">width</span><span class="plain-syntax"> + </span><span class="identifier-syntax">O</span><span class="plain-syntax">.</span><span class="identifier-syntax">z</span><span class="plain-syntax">*</span><span class="identifier-syntax">width</span><span class="plain-syntax">*</span><span class="identifier-syntax">height</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">Geometry::cuboid_volume</span><button class="popup" onclick="togglePopup('usagePopup18')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup18">Usage of <span class="code-font"><span class="function-syntax">Geometry::cuboid_volume</span></span>:<br/>Spatial Map - <a href="4-sm.html#SP30_1">&#167;30.1</a><br/>Render HTML Map - <a href="4-rhm.html#SP1_1">&#167;1.1</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">cuboid</span><span class="plain-syntax"> </span><span class="identifier-syntax">C</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">C</span><span class="plain-syntax">.</span><span class="element-syntax">population</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">width</span><span class="plain-syntax">  = </span><span class="identifier-syntax">C</span><span class="plain-syntax">.</span><span class="element-syntax">corner1</span><span class="plain-syntax">.</span><span class="element-syntax">x</span><span class="plain-syntax"> - </span><span class="identifier-syntax">C</span><span class="plain-syntax">.</span><span class="element-syntax">corner0</span><span class="plain-syntax">.</span><span class="element-syntax">x</span><span class="plain-syntax"> + </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">height</span><span class="plain-syntax"> = </span><span class="identifier-syntax">C</span><span class="plain-syntax">.</span><span class="element-syntax">corner1</span><span class="plain-syntax">.</span><span class="identifier-syntax">y</span><span class="plain-syntax"> - </span><span class="identifier-syntax">C</span><span class="plain-syntax">.</span><span class="element-syntax">corner0</span><span class="plain-syntax">.</span><span class="identifier-syntax">y</span><span class="plain-syntax"> + </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">depth</span><span class="plain-syntax">  = </span><span class="identifier-syntax">C</span><span class="plain-syntax">.</span><span class="element-syntax">corner1</span><span class="plain-syntax">.</span><span class="identifier-syntax">z</span><span class="plain-syntax"> - </span><span class="identifier-syntax">C</span><span class="plain-syntax">.</span><span class="element-syntax">corner0</span><span class="plain-syntax">.</span><span class="identifier-syntax">z</span><span class="plain-syntax"> + </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">width</span><span class="plain-syntax">*</span><span class="identifier-syntax">height</span><span class="plain-syntax">*</span><span class="identifier-syntax">depth</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP15" class="paragraph-anchor"></a><b>&#167;15. </b>Thickening a cuboid is a little more than adjusting; we give it some
extra room. (The result is thus no longer minimally bounding, but we
sacrifice that.)
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Geometry::thicken_cuboid</span><button class="popup" onclick="togglePopup('usagePopup19')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup19">Usage of <span class="code-font"><span class="function-syntax">Geometry::thicken_cuboid</span></span>:<br/>Spatial Map - <a href="4-sm.html#SP30_1">&#167;30.1</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">cuboid</span><span class="plain-syntax"> *</span><span class="identifier-syntax">C</span><span class="plain-syntax">, </span><span class="reserved-syntax">vector</span><span class="plain-syntax"> </span><span class="identifier-syntax">V</span><span class="plain-syntax">, </span><span class="reserved-syntax">vector</span><span class="plain-syntax"> </span><span class="identifier-syntax">S</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">population</span><span class="plain-syntax">++ == </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">corner0</span><span class="plain-syntax"> = </span><a href="4-sg.html#SP7" class="function-link"><span class="function-syntax">Geometry::vec_minus</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">V</span><span class="plain-syntax">, </span><span class="identifier-syntax">S</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">corner1</span><span class="plain-syntax"> = </span><a href="4-sg.html#SP7" class="function-link"><span class="function-syntax">Geometry::vec_plus</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">V</span><span class="plain-syntax">, </span><span class="identifier-syntax">S</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">V</span><span class="plain-syntax">.</span><span class="element-syntax">x</span><span class="plain-syntax"> &lt; </span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">corner0</span><span class="plain-syntax">.</span><span class="element-syntax">x</span><span class="plain-syntax">) </span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">corner0</span><span class="plain-syntax">.</span><span class="element-syntax">x</span><span class="plain-syntax"> = </span><span class="identifier-syntax">V</span><span class="plain-syntax">.</span><span class="element-syntax">x</span><span class="plain-syntax"> - </span><span class="identifier-syntax">S</span><span class="plain-syntax">.</span><span class="element-syntax">x</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">V</span><span class="plain-syntax">.</span><span class="element-syntax">x</span><span class="plain-syntax"> &gt; </span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">corner1</span><span class="plain-syntax">.</span><span class="element-syntax">x</span><span class="plain-syntax">) </span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">corner1</span><span class="plain-syntax">.</span><span class="element-syntax">x</span><span class="plain-syntax"> = </span><span class="identifier-syntax">V</span><span class="plain-syntax">.</span><span class="element-syntax">x</span><span class="plain-syntax"> + </span><span class="identifier-syntax">S</span><span class="plain-syntax">.</span><span class="element-syntax">x</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">V</span><span class="plain-syntax">.</span><span class="identifier-syntax">y</span><span class="plain-syntax"> &lt; </span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">corner0</span><span class="plain-syntax">.</span><span class="identifier-syntax">y</span><span class="plain-syntax">) </span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">corner0</span><span class="plain-syntax">.</span><span class="identifier-syntax">y</span><span class="plain-syntax"> = </span><span class="identifier-syntax">V</span><span class="plain-syntax">.</span><span class="identifier-syntax">y</span><span class="plain-syntax"> - </span><span class="identifier-syntax">S</span><span class="plain-syntax">.</span><span class="identifier-syntax">y</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">V</span><span class="plain-syntax">.</span><span class="identifier-syntax">y</span><span class="plain-syntax"> &gt; </span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">corner1</span><span class="plain-syntax">.</span><span class="identifier-syntax">y</span><span class="plain-syntax">) </span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">corner1</span><span class="plain-syntax">.</span><span class="identifier-syntax">y</span><span class="plain-syntax"> = </span><span class="identifier-syntax">V</span><span class="plain-syntax">.</span><span class="identifier-syntax">y</span><span class="plain-syntax"> + </span><span class="identifier-syntax">S</span><span class="plain-syntax">.</span><span class="identifier-syntax">y</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">V</span><span class="plain-syntax">.</span><span class="identifier-syntax">z</span><span class="plain-syntax"> &lt; </span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">corner0</span><span class="plain-syntax">.</span><span class="identifier-syntax">z</span><span class="plain-syntax">) </span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">corner0</span><span class="plain-syntax">.</span><span class="identifier-syntax">z</span><span class="plain-syntax"> = </span><span class="identifier-syntax">V</span><span class="plain-syntax">.</span><span class="identifier-syntax">z</span><span class="plain-syntax"> - </span><span class="identifier-syntax">S</span><span class="plain-syntax">.</span><span class="identifier-syntax">z</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">V</span><span class="plain-syntax">.</span><span class="identifier-syntax">z</span><span class="plain-syntax"> &gt; </span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">corner1</span><span class="plain-syntax">.</span><span class="identifier-syntax">z</span><span class="plain-syntax">) </span><span class="identifier-syntax">C</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">corner1</span><span class="plain-syntax">.</span><span class="identifier-syntax">z</span><span class="plain-syntax"> = </span><span class="identifier-syntax">V</span><span class="plain-syntax">.</span><span class="identifier-syntax">z</span><span class="plain-syntax"> + </span><span class="identifier-syntax">S</span><span class="plain-syntax">.</span><span class="identifier-syntax">z</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">}</span>
</pre>
<nav role="progress"><div class="progresscontainer">
    <ul class="progressbar"><li class="progressprev"><a href="4-mc.html">&#10094;</a></li><li class="progresschapter"><a href="P-wtmd.html">P</a></li><li class="progresschapter"><a href="1-im.html">1</a></li><li class="progresschapter"><a href="2-il.html">2</a></li><li class="progresschapter"><a href="3-tpt.html">3</a></li><li class="progresscurrentchapter">4</li><li class="progresssection"><a href="4-mc.html">mc</a></li><li class="progresscurrent">sg</li><li class="progresssection"><a href="4-sm.html">sm</a></li><li class="progresssection"><a href="4-rhm.html">rhm</a></li><li class="progresssection"><a href="4-rem.html">rem</a></li><li class="progressnext"><a href="4-sm.html">&#10095;</a></li></ul></div>
</nav><!-- End of weave -->

		</main>
	</body>
</html>

